<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>session对象--登录</title>
</head>
<body>
<%
 	//取得输入的用户名和密码
 	String name = request.getParameter("username");
	String pwd = request.getParameter("password");
	//判断用户名与密码是否正确，默认用户为root,密码为123456
	if(name.equals("root")&&pwd.equals("123456"))
	{
		//设置session属性username，值为用户名
		session.setAttribute("username",name);
		//通过getAttribute()方法获取会话的username属性
		out.print(((String)session.getAttribute("username"))+",欢迎你！");
	}
	else
	{
		out.print("<script type = \"text/javascript\">alert('对不起，用户名或密码错误！');history.go(-1);</script>");
	}
%>
</body>
</html>